// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <ddktl/metadata/touch-buttons.h>
#include <hid/descriptor.h>
#include <hid/visalia-touch.h>

// clang-format off
static const uint8_t touch_buttons_report_desc[] = {
    HID_USAGE_PAGE(0x0C), // Consumer
    HID_USAGE(0x01), // Consumer Control
    HID_COLLECTION_APPLICATION,

    HID_REPORT_ID(BUTTONS_RPT_ID_INPUT),

    HID_USAGE_PAGE(0x0C), // Consumer
    HID_USAGE(0xE9), // Volume Up
    HID_USAGE(0xEA), // Volume Down
    HID_USAGE(0xB1), // Pause
    HID_LOGICAL_MIN(0),
    HID_LOGICAL_MAX(1),
    HID_REPORT_SIZE(1),
    HID_REPORT_COUNT(3),
    HID_INPUT(HID_Data_Var_Abs),
    HID_REPORT_SIZE(5), // Padding
    HID_REPORT_COUNT(1),
    HID_INPUT(HID_Const_Arr_Abs),

    HID_END_COLLECTION,
};
// clang-format on

size_t get_visalia_touch_buttons_report_desc(const uint8_t** buf) {
  *buf = touch_buttons_report_desc;
  return sizeof(touch_buttons_report_desc);
}

void fill_visalia_touch_buttons_report(uint8_t id, bool value,
                                       visalia_touch_buttons_input_rpt_t* rpt) {
  switch (id) {
    case BUTTONS_ID_VOLUME_UP:
      if (value) {
        rpt->volume_up = 1;
      }
      break;
    case BUTTONS_ID_VOLUME_DOWN:
      if (value) {
        rpt->volume_down = 1;
      }
      break;
    case BUTTONS_ID_PLAY_PAUSE:
      if (value) {
        rpt->pause = 1;
      }
      break;
  }
}
